package com.dsdl.chatapp.module.chat;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.dsdl.chatapp.BaseActivity;
import com.dsdl.chatapp.R;
import com.dsdl.chatapp.common.utils.ActivityUtils;

public class ChatWindowActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat_window);
        Intent intent = getIntent();
        String friendPhone = null;
        if (intent.hasExtra("phone")){
            friendPhone = intent.getStringExtra("phone");
        }
        initView();
//        initFragment("17096193425");
        initFragment("18561611656");
    }

    private void initView(){
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_chat_window);
        setSupportActionBar(toolbar);
        initListener(toolbar);
    }
    private void initListener(Toolbar toolbar){
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

    private void initFragment(String phone){
//        ChatWindowFragment chatWindowFragment = (ChatWindowFragment) getSupportFragmentManager().findFragmentById(R.id.chat_contentFrame);
//        if (chatWindowFragment == null){
//            chatWindowFragment = ChatWindowFragment.newInstance();
//            Bundle bundle = new Bundle();
//            bundle.putString("phone",phone);
//            chatWindowFragment.setArguments(bundle);
//            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(),chatWindowFragment,R.id.chat_contentFrame);
//        }
        ChatFragment chatFragment = (ChatFragment) getSupportFragmentManager().findFragmentById(R.id.chat_contentFrame);
        if (chatFragment == null){
            chatFragment = ChatFragment.newInstance();
            Bundle bundle = new Bundle();
            bundle.putString("phone",phone);
            chatFragment.setArguments(bundle);
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(),chatFragment,R.id.chat_contentFrame);
        }
    }
}
